package com.cmsz.shuang.booter.web;

import com.cmsz.shuang.booter.model.UserPo;
import com.vaadin.annotations.Theme;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinSession;
import com.vaadin.spring.annotation.SpringUI;
import com.vaadin.ui.Button;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Button.ClickEvent;

@SpringUI(path="/main")
@Theme("valo")
public class MainFrameUI extends UI {
	
	@Override
	protected void init(VaadinRequest request) {
		UserPo userpo = (UserPo) VaadinSession.getCurrent().getAttribute("UserPO");
		
		Label lab1 = new Label(userpo.getName() + " pwd=" + userpo.getPassword());
		
		String info ="";
		
		if(userpo== null)
		{
			info = "userpo = null";
		}else
		{
			info = "not null";
		}
		
//		Label lab1 = new Label(info);
		
		
		VerticalLayout layout1 = new VerticalLayout();
		layout1.addComponent(lab1);
		
		HorizontalLayout layout2 = new HorizontalLayout();
		
		layout1.addComponent(layout2);
		
		VerticalLayout layout3 = new VerticalLayout();
		VerticalLayout layout4 = new VerticalLayout();
		
		layout3.setWidth("300px");
		
		
		layout2.addComponent(layout3);
		layout2.addComponent(layout4);
		
		Button sbtn1 = new Button("sbtn1");
		Button sbtn2 = new Button("sbtn2");
		Button sbtn3 = new Button("sbtn3");
		
		
		Button cbtn1 = new Button("cbtn1");
		Button cbtn2 = new Button("cbtn2");
		Button cbtn3 = new Button("cbtn3");
		
		layout3.addComponents(cbtn1, cbtn2, cbtn3);
		
		layout4.addComponents(sbtn1,sbtn2,sbtn3);
		
		cbtn1.addClickListener(new Button.ClickListener() {
			
			@Override
			public void buttonClick(ClickEvent event) {
				sbtn1.setVisible( !sbtn1.isVisible());
			}
		});
		
		cbtn2.addClickListener(new Button.ClickListener() {
			
			@Override
			public void buttonClick(ClickEvent event) {
				sbtn2.setVisible( !sbtn2.isVisible());
			}
		});
		
		cbtn3.addClickListener(new Button.ClickListener() {
			
			@Override
			public void buttonClick(ClickEvent event) {
				sbtn3.setVisible( !sbtn3.isVisible());
			}
		});
		
		
		setContent(layout1);
	}

}
